package com.jibei.mendo.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.jibei.mendo.R;
import com.jibei.mendo.adapter.AboutDevAdapter;
import com.jibei.mendo.event.Event;
import com.jibei.mendo.utils.Constant;
import com.jibei.mendo.utils.VibratorUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lhl on 2019/8/24.
 * 关于设备
 */
public class AboutDevActivity extends BaseActivity implements View.OnClickListener {

    private ImageView iv_back;
    private RecyclerView rv_about_dev;
    private List<String> strings = new ArrayList<>();
    private AboutDevAdapter mAboutDevAdapter = new AboutDevAdapter(this, strings);


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_dev);

        iv_back = findViewById(R.id.iv_back);
        iv_back.setOnClickListener(this);

        rv_about_dev = findViewById(R.id.rv_about_dev);
        rv_about_dev.setLayoutManager(new LinearLayoutManager(this));
        rv_about_dev.setAdapter(mAboutDevAdapter);

        initData();
    }

    private void initData() {
        strings.add(getResources().getString(R.string.assembly_factory));
        strings.add(getResources().getString(R.string.manufacturer));
        strings.add(getResources().getString(R.string.server_number));
        strings.add(getResources().getString(R.string.about_device_id)+ android.os.Build.SERIAL);
        strings.add(getResources().getString(R.string.device_verison));
        strings.add(getResources().getString(R.string.FCC_ID));
        mAboutDevAdapter.notifyDataSetChanged();
    }

    @Override
    public boolean onActivityReceiveEvents(Event event) {
        boolean isCaptured = false;//子Activity是否捕获事件
        if (super.onActivityReceiveEvents(event)) {
            return isCaptured;
        }
        isCaptured = true;
        switch (event.getTag()) {
            case Constant.Events.DIAN_HUO:
            case Constant.Events.JIAN_CE:
            case Constant.Events.KONG_DANG:
            case Constant.Events.READY_PRESS:
            case Constant.Events.DIAN_HUO_PRESS:
                finish();
                break;
            default:
                isCaptured = false;
                break;
        }
        return isCaptured;
    }

    @Override
    public void onClick(View v) {
        VibratorUtil.getInstance().executeVibrator(this, 100);
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            default:
                break;
        }
    }
}
